package cn.wolfcode.wolf2w.business.controller;


import cn.wolfcode.wolf2w.business.domain.Strategy;
import cn.wolfcode.wolf2w.business.dto.ChatRequest;
import cn.wolfcode.wolf2w.business.dto.ChatResponse;
import cn.wolfcode.wolf2w.business.service.DeepseekService;
import cn.wolfcode.wolf2w.business.service.StrategyServuice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
public class ChatController {

    @Autowired
    private StrategyServuice strategyService;
    @Autowired
    private DeepseekService deepseekService;

    @PostMapping("/chat")
    ///      接收数据                             /// 发送数据
    public ChatResponse chatResponse(@RequestBody ChatRequest request) throws IOException {
        //1. 查询私有库（es）获取私有数据
        List<Strategy> strategies = strategyService.search(request.getQuestion(), request.getTopK());
        //2. 发送请求到deepseek，获取结果
        String answer = deepseekService.askWithStrategies(request.getQuestion(), strategies);
        //3. 整合结果，并返回
        ChatResponse chatResponse = new ChatResponse(answer, strategies);
        return chatResponse;
    }

}
